package com.example.webviewdemo1;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.aphidmobile.flip.FlipViewController;
import com.aphidmobile.flip.FlipViewController.ViewFlipListener;

public class MainActivity extends Activity {
	protected FlipViewController flipView;
	WebViewDetail mDetail;
	int mHeight = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// setContentView(R.layout.activity_main);
		flipView = new FlipViewController(this);
		flipView.setBackgroundColor(Color.WHITE);

		flipView.setOnViewFlipListener(new ViewFlipListener() {

			@Override
			public void onViewFlipped(View arg0, int arg1) {
				// TODO Auto-generated method stub
				if (mDetail.mWebView.getHeight() > 0) {
					mHeight = mDetail.mWebView.getHeight();
				}
			}
		});

		flipView.setAdapter(new BaseAdapter() {

			@Override
			public View getView(int position, View convertView, ViewGroup parent) {

				if (convertView == null) {
					Log.e("tag", "NULL");
					mDetail = new WebViewDetail(parent.getContext());
					mDetail.loadData();
				} else {
					Log.e("tag", "NOT NULL");
					mDetail = (WebViewDetail) convertView;
				}
				mDetail.scrollTo(mHeight * position);
				Log.e("tag", String.valueOf(position));
				return mDetail;
			}

			@Override
			public long getItemId(int position) {
				// TODO Auto-generated method stub
				return position;
			}

			@Override
			public Object getItem(int position) {
				// TODO Auto-generated method stub
				return position;
			}

			@Override
			public int getCount() {
				// TODO Auto-generated method stub
				return 10;
			}
		});
		setContentView(flipView);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
